package com.itheima.d3_resource;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * 目标：掌握释放资源的方式:try-catch-finally
 */
public class Test1 {
    public static void main(String[] args) {
        File file = new File("day09file-io-app/file/aaa/bbb/img.png");
        File file1 = new File("day09file-io-app/file/qwdw/img.png");
        FileInputStream fis = null;
        FileOutputStream fos = null;

        try {
            fis = new FileInputStream(file);
            fos = new FileOutputStream(file1, true);//追加输出
            int leng;
            byte[] buf = new byte[1024];

            while ((leng = fis.read(buf)) != -1) {
                fos.write(buf);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                fos.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                fis.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
}
